//
//  DecoratorTest.m
//  Charles
//
//  Created by Leo on 2017/6/13.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "DecoratorTest.h"
#import "BehaviorDecorator.h"
#import "Animal.h"
#import "Beverage.h"
#import "BeverageDecorator.h"

@implementation DecoratorTest

- (void)dealloc {
    NSLog(@"%@ dealloc", NSStringFromClass(self.class));
}

+ (void)testClass {
    
    /*
     *  猪具备的行为：地上走、吃、叫喊
     */
    
    Animal * animal = [[Pig alloc]init];
    
    //行为
    Eat *eat = [[Eat alloc]init];
    Shout *shout = [[Shout alloc]init];
    
    eat.component = animal;
    shout.component = eat;
    
    NSString *behavior = [shout behavior];
    NSLog(@"%@ %@",animal.desc,behavior);

    /*
     *  鸟具备的行为：天上飞、地上走、吃、叫喊
     */

    Animal *animal2 = [[Bird alloc]init];
    
    //行为
    Eat *eat1 = [[Eat alloc]init];
    Shout *shout1 = [[Shout alloc]init];
    Run *run = [[Run alloc]init];
    
    run.component = animal2;
    eat1.component = run;
    shout1.component = eat1;
    
    NSString *behavior1 = [shout1 behavior];
    NSLog(@"%@ %@",animal2.desc,behavior1);

}

+ (void)testDelegate {
    id<Beverage> beverage = [[Espresso alloc]init];
    NSLog(@"name：%@ cost：%f",[beverage getName], [beverage cost]);
    
    //添加牛奶调料
    beverage = [[Milk alloc]initWithBeverage:beverage];
    NSLog(@"name：%@ cost：%f",[beverage getName], [beverage cost]);

    //添加摩卡调料
    beverage = [[Mocha alloc]initWithBeverage:beverage];
    NSLog(@"name：%@ cost：%f",[beverage getName], [beverage cost]);

}

@end
